// http.js 封装 axios，防止多处打包
import Axios from "axios";
import config from "./config"; //引入配置文件
import Vue from "vue";
import Cookie from "./cookie";
// 实例化 axios()
const http = Axios.create({
  baseURL: config.api, //根url
  timeout: 8000,
  withCredentials: true,
  validateStatus: function (status) {
    return status >= 200;
  }
});
http.interceptors.request.use(function (config) {
  if (!!Cookie.getCookie("enc_auth_token")) {
    config.headers.common["Authorization"] = "Bearer " + Cookie.getCookie("enc_auth_token");
  }
  config.headers.common[".AspNetCore.Culture"] = "de";
  config.headers.common["Abp.TenantId"] = null;
  return config;
}, function (error) {

  return Promise.reject(error);
});
// http 的response 命令，失败的调用上边的失败异常方法
http.interceptors.response.use(response => {
  if (!response.data.success) {
    alert(123)
    console.log(this)
    Vue.$Message.success("删除成功！vvvvvvvv")
    return
  }
  return response.data
}, err => {
  Vue.$Message.error("网络请求错误");
});
export default http; // 输出http
